#include"msg.hpp"

int main()
{
    cout<<"hello im msg_client.cc"<<endl;
        cout<<"hello im msg_server.cc"<<endl;
    int key=getkey();
   int msgid= Getmsg(key);
    sleep(1);
    cout<<"server create msgqueue success\n"<<endl;
        //接收并打印消息
char buf[1024];
while(true)
{
    buf[0]=0;
    printf("please enter# ");
    fflush(stdout);
    ssize_t s=read(0,buf,sizeof(buf));
    if(s>0)
    {
        buf[s-1]=0;
        sendmsg(msgid,CLIENT_TYPE,buf);
        printf("send done,wait recieve ...\n");
    }
    receivemsg(msgid,SERVER_TYPE,buf);
    printf("server says#: %s\n",buf);
} 

    sleep(1);
    deletemsg(msgid);
     cout<<"server delete msgqueue success\n"<<endl;
    return 0;
}